//
//  SwitchSegmentedControlViewController.swift
//  iOS-RxSwift-Tutorials_Example
//
//  Created by mengru.tian on 2020/9/21.
//  Copyright © 2020 CocoaPods. All rights reserved.
//

import UIKit
import RxSwift

class SwitchSegmentedControlViewController: UIViewController {

    @IBOutlet weak var switchx: UISwitch!
    @IBOutlet weak var button: UIButton!
    @IBOutlet weak var segmented: UISegmentedControl!
    @IBOutlet weak var imageView: UIImageView!
    
    private let disposeBag = DisposeBag()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        title = "22.UI控件扩展4：UISwitch、UISegmentedControl"
        view.backgroundColor = .white
        
        test()
        test2()
    }
    
    // UISwitch（开关按钮）
    func test() {
        switchx.rx.isOn
        .bind(to: button.rx.isEnabled)
        .disposed(by: disposeBag)
    }
    
    // UISegmentedControl（分段选择控件）
    func test2() {
//        //创建一个当前需要显示的图片的可观察序列
//        let showImageObservable: Observable<UIImage> =
//            segmented.rx.selectedSegmentIndex.asObservable().map {
//                let images = ["js.png", "php.png", "react.png"]
//                return UIImage(named: images[$0])!
//        }
//
//        //把需要显示的图片绑定到 imageView 上
//        showImageObservable.bind(to: imageView.rx.image)
//            .disposed(by: disposeBag)
    }

}
